library(graphics)
par(mar=c(4, 4, 2, 0.5), oma=c(1,1,1,1))
#
hist(spikein133, xlim=c(0,16), rainbow(6), freq=TRUE)
par(mar=c(4, 4, 2, 0.5), oma=c(1,1,1,1))
#
''''
hist(spikein133, xlim=c(0,16), rainbow(6), freq=TRUE)
hist(spikein133[1:1000,], xlim=c(0,16), rainbow(6))
dim(spikein133)
hist(spikein133[1:100,], xlim=c(0,16), rainbow(6))
spikein133
hist(spikein133[,1:4], xlim=c(0,16), rainbow(6))
hist(spikein133[1:100,1:4], xlim=c(0,16), rainbow(6))
v=exprs(x)
v=exprs(spikein133)
dim(v0)
dim(v)
hist(v[1:100,1:4], xlim=c(0,16), rainbow(6))
hist(v, xlim=c(0,16), rainbow(6))
hist(v, xlim=c(0,16))
hist(v[,1], xlim=c(0,16))
hist(v[,1], xlim=c(0,16), rainbow(6))
hist(v[,1], xlim=c(0,16), rainbow(4))
hist(v[,1], xlim=c(0,16))
hist(spikein133, xlim=c(0,16), rainbow(6), density=NULL)
library(cluster)
x <- rbind(cbind(rnorm(10, 0, 0.5), rnorm(10, 0, 0.5)),#
           cbind(rnorm(15, 5, 0.5), rnorm(15, 5, 0.5)),#
           cbind(rnorm( 3,3.2,0.5), rnorm( 3,3.2,0.5)))
fannyx <- fanny(x, 2)
plot(fannyx)
plot(fannyx)#
#
(fan.x.15 <- fanny(x, 2, memb.exp = 1.5)) # 'crispier' for obs. 26:28#
(fanny(x, 2, memb.exp = 3))
data(ruspini)#
f4 <- fanny(ruspini, 4)#
stopifnot(rle(f4$clustering)$lengths == c(20,23,17,15))#
plot(f4, which = 1)#
## Plot similar to Figure 6 in Stryuf et al (1996)#
plot(fanny(ruspini, 5))
data(ruspini)#
f4 <- fanny(ruspini, 4)#
stopifnot(rle(f4$clustering)$lengths == c(20,23,17,15))#
plot(f4, which = 1)
plot(fanny(ruspini, 5))
summary(fannyx)
plot(fannyx)
clustplot(fannyx)
clusplot(fannyx)
fannyx <- fanny(x, 5)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =1)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =1.5)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =1.1)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =1.01)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =1.001)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =1.005)
clusplot(fannyx)
fannyx <- fanny(x, 5, memb.exp =2)
clusplot(fannyx)
fannyx <- fanny(x, 3, memb.exp =2)
clusplot(fannyx)
# Question one

library("affy")
library("SpikeInSubset")

data(spikein133)
RD<-AffyRNAdeg(spikein133[,1:4])
plotAffyRNAdeg(RD)
summaryAffyRNAdeg(RD)
expression_MAS = mas5(spikein133)
bf_MAS = exprs(expression_MAS)
hist(log(bf_MAS[,1]), main = "Histogram of logarithm values of the first sample set",
xlab = "log(first sample set)"
)
exit
spike_after_bg_correction = bg.correct(spikein133, method="rma")
hist(spike_after_bg_correction)
exit
q()
p3=phyper(3,287,20000,5)
p3
1-p3
?phyper
phyper(3,287,20000,5)
k<-3
#
n<-5
#
m<-287
#
N<-20000
#
x<-k:n   #draw >=3 marbles k=3,4,5
#
prob<-dhyper(x,m,N-m,n)
prob
cat("Total possibility (P-value) to draw >=k white marbles is:", sum(prob), "\n") #prints the sum of 3 prob.
?dhyper(2,287,2000,5)
dhyper(2,287,2000,5)
phyper(2,287,2000,5)
phyper(3,287,2000,5)
dhyper(3,287,2000,5)
phyper(3,287,2000,5)
dhyper(3,287,2000,5)
phyper(3,287,2000,5, lower.tail=False)
phyper(3,287,2000,5, lower.tail=FALSE)
phyper(2,287,2000,5, lower.tail=FALSE)
phyper(2, 287, 19713, 5, lower.tail=F)
phyper(2, 287, 19713, 5)
phyper(2, 287, 19713, 5, lower.tail=F)
phyper(3, 287, 19713, 5, lower.tail=F)
phyper(4, 287, 19713, 5, lower.tail=F)
phyper(5, 287, 19713, 5, lower.tail=F)
dhyper(3,287,19713,5)
dhyper(3,287,2000,5)
dhyper(3,287,20000,5)
?dhyper
pp=dhyper(19, 495, 27114, 186)
sum(pp)
pp
k=19:186
pp=dhyper(k, 495, 27114, 186)
sum(pp)
k=1:186
pp=dhyper(k, 495, 27114, 186)
sum(pp)
?dhyper
k=19:1400
pp=dhyper(k, 495, 27114, 1400)
sum(pp)
k=19:186
pp=dhyper(k, 495, 3400, 186)
sum(pp)
k=8:186
pp=dhyper(k, 96, 3400, 186)
sum(pp)
k=3:186
pp=dhyper(k, 89, 3400, 186)
sum(pp)
k=55:186
pp=dhyper(k, 531, 3400, 186)
sum(pp)
k=55:1400
pp=dhyper(k, 531, 3400, 1400)
sum(pp)
pp=dhyper(k, 531, 27114, 1400)
sum(pp)
library(edgeR)#
library(stats) #edgeR needs this lib#
library(MASS)
y <- as.matrix(read.table("/Users/chizhang/UNL/Courses/NGS slides/homework/edgeR_example/s_2_3_chr2.dat"))
tags <- as.matrix(read.table("/Users/chizhang/UNL/Courses/NGS slides/homework/edgeR_example/tag_chr2.dat"))
rownames(y)=tags
lib.sizes <- c(13041385, 16428242 )
n=length(tags) #the number of rows
d<- DGEList(counts=y, group=c("water","PEG"), remove.zeros = TRUE)
d <- estimateCommonDisp(d) #
ms <-  exactTest(d)
res=topTags(ms, n=1000, adjust.method= "fdr")
results=res$table;
res
results
res
dim(res)
objects()
res
sort(res)
sort(result)
sort(results)
?sort
results[order((results$logFC)),]
results[order(results$logFC),]
order(results$logFC)
results[order(results$logFC),1]
results[order(results$logFC),2]
results[order(results$logFC),3]
results[order(results$logFC),1:3]
results[order(results$logFC),1:4]
results[order(results$logFC),1:5]
results[order(results$logFC),1:2]
results[order(res$logFC),1:2]
res$log(FC)
res
res=topTags(ms, n=5, adjust.method= "fdr")
res
res=topTags(ms, n=20000, adjust.method= "fdr")
res
?topTags
res$comparison
res=topTags(ms, n=20000, adjust.method= "fdr", sort.by="logFC")
res
res=topTags(ms, n=5, adjust.method= "fdr", sort.by="logFC")
res
?toptags
library(edgeR)
?toptags
??toptags
 library(igraph)
read.graph("/Users/chizhang/Desktop/graph.list",format="edgelist")
myG=read.graph("/Users/chizhang/Desktop/graph.list",format="edgelist")
objets()
objects()
degree(myG)
plot.igraph(myG)
myG=read.graph("/Users/chizhang/Desktop/graph.list",format="edgelist", directed=FALSE)
plot.igraph(myG)
degree(myG)
degree(myG, v=1)
shortest.paths(myGraph, algorithm="dijkstra")
shortest.paths(myG, algorithm="dijkstra")
shortest.paths(myG, from=2, to=3, algorithm="dijkstra")
shortest.paths(myG, v=2, to=3, algorithm="dijkstra")
shortest.paths(myG, v=2,  algorithm="dijkstra")
betweenness(myG, directed = FALSE)
clusters(myG)
clusters(myG, mode="srong")
clusters(myG, mode="strong")
cliques(myG)
plot.igraph(myG)
cliques(myG, min=3)
myT=minimum.spanning.tree(myG)
plot.igrpah(myT)
plot.igraph(myT)
diameter(myG, directed=FALSE)
graph.density(myG)
stMincuts(myG, source=1, target=5)
??stMincuts
?stMincuts
library("affy")
library("SpikeInSubset")

data(spikein133)
boxplot(spikein133, ylim=c(0,15), col=c("red","red","red","green","green","green"))
savePlot("before_bg_correction", type="jpg")
spike_after_bg_correction = bg.correct(spikein133, method="rma")
boxplot(spike_after_bg_correction, ylim=c(0,15), col=c("red","red","red","green","green","green"))
savePlot("after_bg_correction", type="jpg")

#For question 1B
hist(spike_after_bg_correction)
hist(spike_after_bg_correction)
hist(spikein133)
>library(stats)  #edgeR needs this lib
 >setwd("/Users/chizhang/UNL/Courses/BIOS897-1 Spring 2013/homework/HW6")
library(stats)  setwd("/Users/chizhang/UNL/Courses/BIOS897-1 Spring 2013/homework/HW6"
library(stats)  setwd("/Users/chizhang/UNL/Courses/BIOS897-1 Spring 2013/homework/HW6")
library(stats)
setwd("/Users/chizhang/UNL/Courses/BIOS897-1 Spring 2013/homework/HW6")
>set.seed(111)
set.seed(111)
y <- as.matrix(read.table("RNA_seq_data.txt"))
tags <- as.matrix(read.table("tags.txt"))
rownames(y)=tags
sum(y)
sum(y[,1])
lib.sizes <- c(sum(y[,1]),sum(y[,2]),sum(y[,3]),sum(y[,4]),sum(y[,5]), sum(y[,6]))
lib.sizes
d<-DGEList(counts=y, group=factor(c(”Ctr",”Ctr",”Ctr",”Tr",”Tr”,”Tr”)), remove.zeros = TRUE)
d<-DGEList(counts=y, group=factor(c("C","C","C","T","T","T")), remove.zeros = TRUE)
library(edgeR)
d<-DGEList(counts=y, group=factor(c("C","C","C","T","T","T")), remove.zeros = TRUE)
d<-estimateCommonDisp(d)
ms<-exactTest(d)
result=topTags(ms, n=???, adjust.method= "fdr")
result=topTags(ms, n=39656, adjust.method= "fdr")
?topTags
result=topTags(ms, n=39656, adjust.method= "fdr", sort.by="LogFC")
result
result=topTags(ms, n=5, adjust.method= "fdr", sort.by="LogFC")
result
dim()result$table)
dim(result$table)
result=topTags(ms, n=39656, adjust.method= "fdr", sort.by="LogFC")
dim(result$table)
result$table[28934-28939,]
result$table[28934:28939,]
result=topTags(ms, n=20, adjust.method= "fdr", sort.by="LogFC")
result
result=topTags(ms, n=200, adjust.method= "fdr", sort.by="LogFC")
result
result=topTags(ms, n=200, adjust.method= "fdr", sort.by="logFC")
result
plot(result$table[,2], -log2(result$table[,3]))
result=topTags(ms, n=39656, adjust.method= "fdr", sort.by="LogFC")
plot(result$table[,2], -log2(result$table[,3]))
plot(result$table[,1], -log2(result$table[,3]))
result$table
head(result$table)
result=topTags(ms, n=39656, adjust.method= "fdr", sort.by="logFC")
head(result$table)
plot(result$table[,1], -log2(result$table[,3]))
results
result
